<%@page import="objects.Player"%>
<%@page import="objects.ConfigurationType"%>
<%@page import="objects.Board"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<script src="scripts/jquery-1.9.0.min.js" type="text/javascript"></script>
<script src="scripts/jquery.contextMenu.js" type="text/javascript"></script>
<script src="scripts/createGame.js" type="text/javascript"></script>
    <dl>
        <dd>
        	<% if (Board.getInstance().isGameStarted()) { %>
        	
        		Sorry, the game has already started
        		
        	<% } else if (Board.getInstance().isGameInitialized()) { %>
        	
        		<form action="Join" method="GET">
        	
        		<% if (Board.getInstance().getBdGameData().getType().equals(ConfigurationType.MANUAL)) { %>
        		
        		Other player has already chose the configuration, you can join his game by inserting your name and pressing join
        			
        			<input type="text" name="browserPlayer"/>
        		
        			<%} else { %>
        			
        				<%if (request.getAttribute("creator") != null && request.getAttribute("creator").equals(true)) { %>
        				 Please choose your name
        				  <%} else { %>
        				 Other player has already chose the configuration, you can join his game by choosing your name and pressing join
        					<%}%>
        					<input type="hidden" value=<%=request.getAttribute("creator")%> name="creator"/>
        				 
        				  <select name="browserPlayer">
        				  <%
                          for (Player currPlayer : Board.getInstance().getBdGameData().getPlayers()) {
                              String playerName = currPlayer.getPlayerName();
                              
                              if (!currPlayer.isOccupied() && currPlayer.getType().equals("HUMAN")) {
    				  %>
	                          <option value="<%=playerName%>"><%=playerName%></option>
    				  <%
    				                              }
    				                          }
    				  %>
    				                      </select> 
        				
        			
        			<%}%>
        				<input type="submit" value="join" />
        			
        			<br/>
        			<% if (request.getAttribute("errorMsg") != null) { %>
        				<%= request.getAttribute("errorMsg") %>
        			<% } %>
        		</form>
        	<% } else { %>
        	<table class="fullYellow">
	        	<tr>
	        		<td align="center">
	        			<form id="manual">
	        				<table class="half"> 
	        					<tr> 
	        						<td colspan="3" align="center">
										<label> Initialize manually: </label>
									</td>
								</tr>
								<tr>	
									<td align="center">
										<label> please enter number of players: (3-6)</label>
							            <input type="text" id="numOfPlayers" />
						            </td>
						            <td align="center">
							            <label> please enter number of computer players: </label>
							            <input type="text" id="numOfComputerPlayers" />
						            </td>
						            <td align="center">
							            <label> please enter your name: </label>
							            <input type="text" id="name" />
						            </td>
				            	</tr>
				            	<tr>
				           		 	<td align="center" colspan="3">
				           		 		<input type="submit" value="Start with manual configurations" />
				           		 	</td>
				           		 </tr>
				            </table>
				        </form>
	           		</td>
	           	</tr>
	           	<tr>
	           		<td align="center">
	           			<b>OR </b>
	           		</td>
	           	</tr>
	           	<tr>
	           		<td align="center">
	           			<form action="CreateGameXml" enctype="multipart/form-data" method="POST">
				           	<table class="full">
				           		<tr>
				           			<td align="center">
										<label> Intialize by xml: </label>
									</td>
								<tr>
									<td align="center">
										<input type="file" name="file" id="fileButton">
				           		 	</td>
				           		 </tr>
				           		 <tr>
				           		 	<td align="center">
				           		 		<input type="submit" value="Start with file configurations" />
				           		 	</td>
				           		 </tr>
				           		 <tr>
				           		 	<td align="center">
				           		 		<% if (request.getAttribute("errorMsg") != null) { %>
        				<%= request.getAttribute("errorMsg") %>
        			<% } %>
				           		 	</td>
				           		 </tr>
			           		 </table>
						</form>
					</td>
				</tr>
			</table> 
			<% } %>
        </dd>    
    </dl>
<script type="text/javascript">
    $(document).ready(function() {
        // Call js specific for this page
        newGameJS();
    });
</script>